package com.yc.yyds.servlet;

import com.google.gson.Gson;
import com.yc.yyds.dao.Userdao;
import com.yc.yyds.Bean.Result;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "FreezeServlet", value = "/FreezeServlet.s")
public class FreezeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String freeze = request.getParameter("freeze");
        String userid = request.getParameter("userid");
        Result result;
        Userdao dao=new Userdao();

        try{
            if(freeze.equals("0")){
                dao.modify1(userid,freeze);
                result=new Result(0,"账户冻结成功",null);
            }else{
                dao.modify1(userid,freeze);
                result=new Result(1,"账户解冻成功",null);
            }
        }catch (Exception e){
            e.printStackTrace();
            result=new Result(0,"账户冻结失败",null);
        }
        String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
